<include file="Common:header"/>
<body>
	<div class="edit_con">
		<div class="bannerbaowei">
			<div class="dajianxi"></div>
			<div class="tit1h4391">设置文字广告</div>
		</div>
		<div class="edit_area">
				<div class="banner_word">
					<p>广告文字：</p>
					<input type="text" name="title" class="write_area" value="<{$ad['title']}>" style="border:2px solid #2ebc82">
					<p class="clear_word" onclick="clear_word()" style="background-color:#2ebc82">清空文字</p>
				</div>
				<div class="clear"></div>
				<div class="link_address">
					<p>链接地址：（点击广告跳转到此地址）</p>
					<input type="text" name="url" class="link_write" value="<{$ad['url']}>" style="border:2px solid #2ebc82">
					<div class="link_btn">
						<p class="add_link" style="background-color:#2ebc82" onclick="popularize_url()">插入推广链接</p>
						<p class="clear_link" onclick="clear_link()" style="background-color:#2ebc82">清空网址</p>
					</div>					
				</div>
				<div class="clear"></div>
				<div class="btn_area">
					<input onclick="commit(this)" class="banner_sub" value="提交" style="text-align:center">
					<input type="hidden" value="<{$ad['id']}>" id="tid"> 
					<input type="hidden" id ="upload">
				</div>
		</div>
		<include file="Common:menu"/>
	</div>
</body>
</html>
<script>
	//提交
	function commit(obj){
		var title = $('input[name="title"]').val();
		var url   = $('input[name="url"]').val();
		var tid   = $('#tid').val();
		var image = $('#upload').val();
		if($(obj).attr('readonly')){
			return false;
		}
		$(obj).attr('readonly','readonly');
		$.ajax({
		   type: "POST",
		   url: "<{:U('Home/Template/ajax_word')}>",
		   data: "title="+title+"&url="+url+"&id="+tid+"&type=0&thumb="+image,
		   success: function(msg){
				if(msg.status == '1'){
					layer.open({
						content:'广告保存成功',
						btn: ['确认'],
						yes:function(){
						   window.location.href = msg.url;
						}
					});
			    }else{
					layer.open({
						content:msg.msg
					});
				}
				$(obj).removeAttr('readonly');
		   }
		});
	}
	
	//清空文字
	function clear_word(){
		$('input[name="title"]').val('');
	}
	
	//清除链接
	function clear_link(){
		$('input[name="url"]').val('');
	}
	
	//上传图片
	$('#upload_picture').change(function (){
		$('#upload').submit();
	});
	
	//指向图片
	function picture_src(picture_url){
		$('#picture_src').append('<img src="'+picture_url+'">');
		$('#upload').val(picture_url);
	}
	
	//清除图片
	function clear_picture(){
		$('#picture').remove();
	}
	
	//推广链接
	function popularize_url(){
		var popularize_url = "<{$member_info['spread_url']}>";
		$('input[name="url"]').val(popularize_url);
	}
	
</script>